<template>
    <div class="app-container calendar-list-container">
        <!-- 查询和其他操作 -->
        <div class="filter-container">
            <el-input clearable  style="width: 200px;" placeholder="平台编号" v-model="listQuery.platformId"></el-input>
            <el-select v-model="listQuery.commentModuleNo" placeholder="请选择模块" clearable="">
                <el-option label="社区" value="01"> </el-option>
                <el-option label="卖朋友" value="02"> </el-option>
                <el-option label="活动" value="03"> </el-option>
            </el-select>
            <el-button class="filter-item" type="primary" v-waves icon="el-icon-search" @click="handleFilter">查询</el-button>
        </div>

        <!-- 查询结果 -->
        <el-table size="small" :data="list" v-loading="listLoading" element-loading-text="正在查询中。。。" border fit highlight-current-row>
          <el-table-column align="center" min-width="120px" label="平台编号" prop="platformId">
          </el-table-column>  
          <el-table-column align="center" min-width="120px" label="商户号" prop="merchantId">
          </el-table-column>
          <el-table-column align="center" min-width="100px" label="模块" prop="commentModuleNo">
              <template slot-scope="scope">
                  <span v-if="scope.row.commentModuleNo == '01'">社区</span>
                  <span v-if="scope.row.commentModuleNo == '02'">卖朋友</span>
                  <span v-if="scope.row.commentModuleNo == '03'">活动</span>
              </template>
          </el-table-column>
          <el-table-column align="center" min-width="100px" label="评论类型" prop="commentType">
              <template slot-scope="scope">
                  <span v-if="scope.row.commentType == '1'">评论</span>
                  <span v-if="scope.row.commentType == '2'">回复</span>
              </template>
          </el-table-column>
          <el-table-column align="center" min-width="200px" label="评论内容" prop="commentContent">
          </el-table-column>
          <el-table-column align="center" min-width="150px" label="发表评论的用户昵称" prop="commentByName">
          </el-table-column>       
          <el-table-column align="center" min-width="150px" label="发表评论的用户id" prop="customerId">
          </el-table-column>
          <el-table-column align="center" min-width="150px" label="评论时间" prop="commentTime" sortable="">
          </el-table-column>
          <el-table-column align="center" label="操作" width="150" class-name="small-padding fixed-width">
              <template slot-scope="scope">
                <el-button type="danger" size="mini" v-if="comment_btn_del"  @click="handleDelete(scope.row)">删除</el-button>
              </template>
          </el-table-column>
        </el-table>

        <!-- 分页 -->
        <div class="pagination-container">
            <el-pagination background @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="listQuery.page"
                :page-sizes="[10,20,30,50]" :page-size="listQuery.limit" layout="total, sizes, prev, pager, next, jumper" :total="total">
            </el-pagination>
        </div>
    </div>
</template>

<script>
import waves from '@/directive/waves' // 水波纹指令
import { listComment, deleteComment } from '@/api/cms/comment/index'
import { mapGetters } from 'vuex'

export default {
  name: 'viewpoint',
  directives: {
    waves
  },
  data() {
    return {
      listQuery: {
        page: 1,
        limit: 10,
        commentModuleNo: '',
        platformId: ''
      },
      viewTypes: [
        {
          label: '社区',
          value: '01'
        },
        {
          label: '卖朋友',
          value: '02'
        }
      ],
      list: [],
      total: 0,
      listLoading: false,
      downloadLoading: false,
      comment_btn_del: false
    }
  },
  created() {
    this.getList()
    this.comment_btn_del = this.elements['commentManager:btn_del']
  },
  computed: {
    ...mapGetters([
      'elements',
      'name'
    ])
  },
  methods: {
    handleFilter() {
      this.listQuery.page = 1
      this.getList()
    },
    handleSizeChange(val) {
      this.listQuery.limit = val
      this.getList()
    },
    handleCurrentChange(val) {
      this.listQuery.page = val
      this.getList()
    },
    handleDelete(row) {
      this.$confirm('此操作将删除选中评论, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(() => {
          deleteComment(row)
            .then(response => {
              console.log(response)
              if (response.success) {
                this.$notify({
                  title: '成功',
                  message: '操作成功',
                  type: 'success',
                  duration: 2000
                })
                this.getList()
              }
            })
        })
    },
    getList() {
      this.listLoading = true
      this.listQuery.platformId = this.platformId
      listComment(this.listQuery).then(response => {
        console.log(response)
        this.list = response.data.rows
        this.total = response.data.total
        this.listLoading = false
      }).catch(() => {
        this.list = []
        this.total = 0
        this.listLoading = false
      })
    }
  }
}
</script>

<style>

</style>